﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Engine.Classes {
    import flash.events.*;
    import flash.display.*;
    import flash.utils.*;
    import flash.system.*;
    import flash.net.*;
    import deng.fzip.*;

    public class ZipArchiveLoader extends Loader {

        private static var m_zips:Dictionary = new Dictionary();

        private var m_filename:String;
        private var m_url:String;
        private var m_context:LoaderContext;
        private var m_loading:Boolean;

        public function ZipArchiveLoader(_arg1:String){
            this.m_filename = _arg1;
            this.m_url = null;
            this.m_context = null;
            this.m_loading = false;
        }
        public function get retryCount():int{
            var _local1:ZipArchiveData = this.getZipData();
            if (_local1 !== null){
                return (_local1.retryCount);
            };
            return (0);
        }
        public function set retryCount(_arg1:int):void{
            var _local2:ZipArchiveData = this.getZipData();
            if (_local2 !== null){
                _local2.retryCount = _arg1;
            };
        }
        public function get errorLogged():Boolean{
            var _local1:ZipArchiveData = this.getZipData();
            if (_local1 !== null){
                return (_local1.errorLogged);
            };
            return (false);
        }
        public function set errorLogged(_arg1:Boolean):void{
            var _local2:ZipArchiveData = this.getZipData();
            if (_local2 !== null){
                _local2.errorLogged = _arg1;
            };
        }
        override public function load(_arg1:URLRequest, _arg2:LoaderContext=null):void{
            if (this.m_loading){
                this.close();
            };
            this.m_url = _arg1.url;
            this.m_context = _arg2;
            this.m_loading = true;
            var _local3:ZipArchiveData = this.getZipData();
            if (_local3 === null){
                _local3 = new ZipArchiveData(_arg1);
                m_zips[_arg1.url] = _local3;
            };
            _local3.load(this.m_filename, {
                onComplete:this.onComplete,
                onHttpStatus:this.defaultHandler,
                onError:this.defaultHandler,
                onSecurityError:this.defaultHandler
            });
        }
        override public function close():void{
            if (!this.m_loading){
                throw (new Error("Called close without first calling load"));
            };
            var _local1:ZipArchiveData = this.getZipData();
            if (_local1 === null){
                throw (new Error("Called close without first calling load"));
            };
            if (_local1.isLoaded(this.m_filename)){
                super.close();
            } else {
                _local1.close(this.m_filename);
            };
            this.m_loading = false;
        }
        private function getZipData():ZipArchiveData{
            if (((!((this.m_url === null))) && (!((m_zips[this.m_url] === undefined))))){
                return (m_zips[this.m_url]);
            };
            return (null);
        }
        private function onComplete(_arg1:FZipEvent):void{
            var _local2:LoaderContext;
            if (this.m_context != null){
                _local2 = new LoaderContext();
                _local2.applicationDomain = this.m_context.applicationDomain;
            };
            super.loadBytes(_arg1.file.content, _local2);
        }
        private function defaultHandler(_arg1:Event):void{
            super.dispatchEvent(_arg1.clone());
        }

    }
}//package Engine.Classes 

import flash.events.*;
import flash.utils.*;
import __AS3__.vec.*;
import flash.net.*;
import deng.fzip.*;

class ZipArchiveData {

    private var m_zip:FZip;
    private var m_request:URLRequest;
    private var m_callbacks:Dictionary;
    private var m_retryCount:int;
    private var m_errorLogged:Boolean;

    public function ZipArchiveData(_arg1:URLRequest){
        this.m_zip = null;
        this.m_request = _arg1;
        this.m_callbacks = new Dictionary();
        this.m_retryCount = 0;
        this.m_errorLogged = false;
        this.initLoad(true);
    }
    public function load(_arg1:String, _arg2:Object):void{
        if ((((this.m_zip === null)) && ((this.m_retryCount >= LoaderConstants.MAX_RETRIES)))){
            throw (new Error("Trying to load when already over the retry max"));
        };
        if (this.m_zip === null){
            this.initLoad();
        };
        var _local3:FZipFile = this.m_zip.getFileByName(_arg1);
        if (_local3 !== null){
            if (_arg2.onComplete !== null){
                _arg2.onComplete(new FZipEvent(FZipEvent.FILE_LOADED, _local3));
            };
            return;
        };
        var _local4:Vector.<Object> = this.m_callbacks[_arg1];
        if (_local4 === null){
            _local4 = new Vector.<Object>();
            this.m_callbacks[_arg1] = _local4;
        };
        _local4.push(_arg2);
    }
    public function close(_arg1:String):void{
        if (this.m_callbacks[_arg1] !== null){
            delete this.m_callbacks[_arg1];
        };
        if (DictionaryUtilInternal.isEmpty(this.m_callbacks)){
            if (this.m_zip !== null){
                this.m_zip.close();
                this.removeEventListeners();
                this.m_zip = null;
            };
        };
    }
    public function isLoaded(_arg1:String):Boolean{
        if (((!((this.m_zip === null))) && (!((this.m_zip.getFileByName(_arg1) === null))))){
            return (true);
        };
        return (false);
    }
    public function get retryCount():int{
        return (this.m_retryCount);
    }
    public function set retryCount(_arg1:int):void{
    }
    public function get errorLogged():Boolean{
        return (this.m_errorLogged);
    }
    public function set errorLogged(_arg1:Boolean):void{
        this.m_errorLogged = _arg1;
    }
    private function onComplete(_arg1:Event):void{
        this.m_callbacks = new Dictionary();
    }
    private function onFileLoaded(_arg1:FZipEvent):void{
        var _local4:Object;
        var _local2:String = _arg1.file.filename;
        var _local3:Vector.<Object> = this.m_callbacks[_local2];
        if (_local3 !== null){
            for each (_local4 in _local3) {
                if (_local4.onComplete !== null){
                    _local4.onComplete(_arg1.clone());
                };
            };
            delete this.m_callbacks[_local2];
        };
    }
    private function onHttpStatus(_arg1:HTTPStatusEvent):void{
        this.handleCallback("onHttpStatus", _arg1);
    }
    private function onError(_arg1:IOErrorEvent):void{
        this.onLoadFail();
        this.handleCallback("onError", _arg1);
    }
    private function onParseError(_arg1:FZipErrorEvent):void{
        this.onError(new IOErrorEvent(_arg1.type, _arg1.bubbles, _arg1.cancelable, _arg1.text));
    }
    private function onSecurityError(_arg1:IOErrorEvent):void{
        this.onLoadFail();
        this.handleCallback("onSecurityError", _arg1);
    }
    private function handleCallback(_arg1:String, _arg2:Event):void{
        var _local3:Vector.<Object>;
        var _local4:Object;
        for each (_local3 in this.m_callbacks) {
            if (_local3 !== null){
                for each (_local4 in _local3) {
                    if (_local4.hasOwnProperty(_arg1)){
                        var _local9 = _local4;
                        _local9[_arg1](_arg2.clone());
                    };
                };
            };
        };
    }
    private function initLoad(_arg1:Boolean=false):void{
        if (this.m_zip !== null){
            throw (new Error("FZip instance already exists"));
        };
        if (!_arg1){
            this.m_retryCount++;
        };
        this.m_zip = new FZip();
        this.addEventListeners();
        this.m_zip.load(this.m_request);
    }
    private function onLoadFail():void{
        this.removeEventListeners();
        this.m_zip = null;
    }
    private function addEventListeners():void{
        this.m_zip.addEventListener(Event.COMPLETE, this.onComplete);
        this.m_zip.addEventListener(FZipEvent.FILE_LOADED, this.onFileLoaded);
        this.m_zip.addEventListener(HTTPStatusEvent.HTTP_STATUS, this.onHttpStatus);
        this.m_zip.addEventListener(IOErrorEvent.IO_ERROR, this.onError);
        this.m_zip.addEventListener(FZipErrorEvent.PARSE_ERROR, this.onParseError);
        this.m_zip.addEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onSecurityError);
    }
    private function removeEventListeners():void{
        this.m_zip.removeEventListener(Event.COMPLETE, this.onComplete);
        this.m_zip.removeEventListener(FZipEvent.FILE_LOADED, this.onFileLoaded);
        this.m_zip.removeEventListener(HTTPStatusEvent.HTTP_STATUS, this.onHttpStatus);
        this.m_zip.removeEventListener(IOErrorEvent.IO_ERROR, this.onError);
        this.m_zip.removeEventListener(FZipErrorEvent.PARSE_ERROR, this.onParseError);
        this.m_zip.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, this.onSecurityError);
    }

}
class DictionaryUtilInternal {

    public function DictionaryUtilInternal(){
    }
    public static function isEmpty(_arg1:Dictionary):Boolean{
        var _local2:Object;
        for each (_local2 in _arg1) {
            return (false);
        };
        return (true);
    }

}
